home *** CD-ROM | disk | FTP | other *** search
- #ifndef _MIC_MEMORY_
- #define _MIC_MEMORY_
-
- //#include <fstream.h>
- #include "mic_main.h"
- #include "mic_data_path.h"
-
- #define kMaxRAM 4096
-
- extern class Mic_1_Class;
- class MemoryClass;
-
- /*
- IMPORTANT! Call InitMicMemory after creating a MemoryClass object.
- I do this to enable a return value for error handling, since I am
- reading an initialization file from a volume.
-
- NOTES: The two temporary input variables "addr" and "word" govern the interaction
- between the main memory and the MBR. When "addr" is updated, main memory
- outputs the word at the address held in the contents of "addr". When "word" is
- updated, it must have been sent from the MBR, which means it should be written.
- Thus, the contents of "word" are written to main memory at the address held in
- the contents of "addr". The clock cycle ensures that the MAR does its work before
- the MBR so that there will always be an address to write to.
- */
- class MemoryClass
- {
- private:
- unsigned short addr;
- unsigned short word;
- unsigned short mem[kMaxRAM];
-
- public:
- MemoryClass() {addr = 0; word = 0;}
-
- unsigned short getNthWord (short n) {if ((n>=0) && (n<kMaxRAM)) return mem[n]; else return 0;}
- Boolean putNthWord (short n, unsigned short newWord);
-
- void input_MAR (Mic_1_Class& Mic, unsigned short newAddr) {addr = newAddr; output(Mic);}
- void input_MBR (Mic_1_Class& Mic, unsigned short newWord) {word = newWord; putNthWord(addr, word);}
- void output (Mic_1_Class& Mic);
- friend ostream& operator << (ostream& s, MemoryClass& m);
- friend istream& operator >> (istream& s, MemoryClass& m);
- };
- //ostream& operator << (ostream& s, MemoryClass& m);
- //istream& operator >> (istream& s, MemoryClass& m);
-
- //prototypes
- short InitMicMemory (Mic_1_Class& Mic);
-
- #endif